#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
/*MAXRESERVED = the number of reserved words*/
#define MAXRESERVED 8
typedef enum{
  IF,THEN,ELSE,END,REPEAT,UNTIL,READ,WRITE,
  PLUS,MINUS,MUL,DIV,EQUAL,LESS,LBRACKET,RBRACKET,SEMI,
  ASSIGN,
  ENDFILE,ERROR,
  NUM,ID
}TokenType;

extern FILE* source;
extern FILE* listing;
extern FILE* code;

extern int lineno;
/***************************************************/
/************** Syntax tree for parsing ************/
/***************************************************/
typedef enum{StmtK, ExpK} NodeKind;
typedef enum{IfK, RepeatK, AssignK, ReadK, WriteK} StmtKind;
typedef enum{OpK, ConstK, IdK} ExpKind;

typedef enum{Void, Integer, Boolean} ExpType;

#define MAXCHILDREN 3

typedef struct treeNode
{
  struct treeNode *child[MAXCHILDREN];
  struct treeNode *sibling;
  int lineno;
  NodeKind nodekind;
  union {StmtKind stmt; ExpKind exp;} kind;
  union {TokenType op;
    int val;
    char *name;}attr;
  ExpType type;
}TreeNode;
